package com.pwt.repository;

import com.pwt.common.ResultPage;
import com.pwt.entity.ProductManage;
import com.pwt.model.ProductManagePOJO;
import com.pwt.repository.base.DataRepositoryExtension;
import org.apache.commons.lang3.StringUtils;

/**
 * @author dw
 * @version 1.0.0
 * @date 2021/9/1
 */
public class ProductManageRepositoryExtensionImpl extends DataRepositoryExtension<ProductManage, String> implements ProductManageRepositoryExtension{


    @Override
    public ResultPage<ProductManagePOJO> getList(String name,Integer offset,Integer limit) {
        String sql =    " SELECT" +
                        " t.TETEIL teteil," +
                        " t.TEBEZEICH name," +
                        " pm.color color," +
                        " pm.create_time createTime ," +
                        " STUFF(( SELECT ',' + MEMERKNR from  MERKMAL m  where  m.METEIL=t.TETEIL  FOR XML PATH ( '' ) ),1,1,'' ) as memerknrIds," +
                        " STUFF(( SELECT ',' + MEMERKBEZ from  MERKMAL m  where  m.METEIL=t.TETEIL  FOR XML PATH ( '' ) ),1,1,'' ) as memerkbezNames" +
                        " FROM" +
                        " TEIL t" +
                        " LEFT JOIN product_manage pm ON t.TETEIL = pm.teteil ";
        String cSql = " select count(1) from TEIL ";
        if(StringUtils.isNotBlank(name)){
            sql +=" where t.TEBEZEICH like N'%"+name+"%'";
            cSql +=" where TEBEZEICH like N'%"+name+"%'";
        }
        return super.queryCustomBeanPageBySql(ProductManagePOJO.class,cSql,sql,offset-1,limit);
    }
}
